/**2014-4-9  吕春城
 * 管理系统的JS代码
 */
function loading($msg){
    if($msg){
        $('#loading').find('loading').text($msg);
    }
    $('#loading').show();
}
function done(){
    $('#loading').hide();
}



var Vote = {
    LinkUrl: undefined,
    updatePass: function () {
        var passpre = $('#prepass').val();
        var pass1 = $('#password1').val();
        var pass2 = $('#password2').val();
        if (pass1 != pass2) {return alert('密码应该输出一致');}
        $.get(Vote.LinkUrl + 'UpdatePass',{"pass0":passpre,"pass1":pass1,"pass2":pass2}, function (data) {
            alert(data);
           
        });
    },
    updateClass: function () {
        var content = '';
        $('#class_list').find('.myclass').each(function () {
            var classid = this.name;
            var name = this.value;
            content += ',' + name+ '|' + classid;
        });
        $("#classinfo").text("正在修改，请稍后");
        loading();
        $.get(Vote.LinkUrl + 'UpdateClass', { "content": content }, function (data) {
            done();
            $("#classinfo").text("");  alert(data);
        });

    },
    updateItem: function () {
        var content = '';
        loading();
        $('#item_list').find('.myitem').each(function () {
            done();
            var classid = this.name;
            var name = this.value;
            content += ',' + name + '|' + classid;
        });
        $("#iteminfo").text('正在修改，请稍后');
        $.get(Vote.LinkUrl + 'UpdateItem', { "content": content }, function (data) {
            $("#iteminfo").text(''); alert(data);
        });
    },
    updateScore: function () {
        var content = '';
        $('#score_list').find('.myscore').each(function () {
            var classid = this.name;
            var name = this.value;
            content += ',' + name + '|' + classid;
        });
        $("#scoreinfo").text('正在修改，请稍后');
        loading();
        $.get(Vote.LinkUrl + 'UpdateScore', { "content": content }, function (data) {
            done();
            alert(data);
            $("#scoreinfo").text('');
        });
    },
    ClearData: function() { //清空数据
        if (confirm("确定要清空所有数据吗？（包括IP记录数据和已经评分的记录）")) {
            loading();
         $.get(Vote.LinkUrl+'ClearData',function(data){
             done();
        	 alert('已经清空数据');
        	 var result='置零评价数据条数'+data.scoreeffect+'  删除限制数据条数：'+data.limitinit;
        	 $('#clearResult').text(result);
         });
        }
    },
    SetTime:function(){
    	var starttime=$('#TextStart').val();
    	var endtime=$('#TextEnd').val();
        loading();
       $.get(Vote.LinkUrl+'setTime',{"time_start":starttime,"time_end":endtime},function(data){
           done();
    	   if(data){alert('设置成功,重启浏览器后生效');}
    	   else{alert('设置失败');}
       });
    },
    SetContent: function() { //设置文本编辑器内容
       var content=  editor.html();
        loading();
        $.get(Vote.LinkUrl+'setInstruction',{"content":content},function(data){
            done();
     	   if(data){alert('设置成功');}
     	   else{alert('设置失败');}
        });
    },
    Setlimit: function () {

        var value = $('#limitnumber').val();
        loading();
        $.get(Vote.LinkUrl + 'setLimit', { "limit":value}, function (data) {
            done();
            if (data) { alert('设置成功,重启浏览器后生效'); }
            else { alert('设置失败'); }
        });
    },
    Inition: function() {
        // 左侧菜单效果 局部折叠
        $('.Menu').click(function() {
            var $NowMenu = $(this).next('.MenuNote');
            $('.MenuNote').hide(400, function() { });
            if ($NowMenu.is(":visible")) {
                $NowMenu.hide(300, function() { });
            } else {
                $NowMenu.show(500, function() { });
            }
        });
        //总体折叠效果
        $("#menu_fold").toggle(
	function() {
	    $("#left_nav").width(26).height(62).children("[class!=menu_fold]").hide();
	    $(this).width(25).height(62).css('background-image', 'url(/NewVote/public/Home/Manager/common/images/menu_folded_bg.png)');
	    $(this).children("span.menu_fold_icon").css('background-image', 'url(/NewVote/public/Home/Manager/common/images/open_icon.png)')
	},
	function() {
	    $("#left_nav").width(184).children().show();
	    $(this).width(183).height(29).css('background-image', 'url(/NewVote/public/Home/Manager/common/images/menu_fold_bg.png)');
	    $(this).children("span.menu_fold_icon").css('background-image', 'url(/NewVote/public/Home/Manager/common/images/close_icon.png)')
	});

    }
};
